package cn.dnui_zll731.dnuifood_731zlll.Adapter;
import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;
import com.squareup.picasso.Picasso;

import java.util.List;

import cn.dnui_zll731.dnuifood_731zlll.common.Constants;
import cn.dnui_zll731.dnuifood_731zlll.R;
import cn.dnui_zll731.dnuifood_731zlll.bean.ShopBean;
import cn.dnui_zll731.dnuifood_731zlll.controller.FoodListActivity;

public class ShopAdapter extends RecyclerViewAdapter<ShopAdapter.shopViewHolder>{

    public ShopAdapter(Context context,List data,int layoutResource) {
        super(context,data,layoutResource);
        Log.d("调试", "onSuccess: 3");
    }


    @Override
    public void onBindViewHolder(ShopAdapter.shopViewHolder shopViewHolder, int position) {
        //负责将每个子项holder绑定数据。俩参数分别是RecyclerView.ViewHolder holder, int position；
        Log.d("调试", "onSuccess: 4");
        final ShopBean shopBean = (ShopBean) data.get(position);

        shopViewHolder.res_name.setText(shopBean.getShopname());
        shopViewHolder.res_address.setText(shopBean.getAddress());
//        shopViewHolder.res_bar.setRating(shopBean.getLevel());
        Log.d("tiaoshi",shopBean.getLevel().toString());
        shopViewHolder.res_bar.setRating(shopBean.getLevel());
        if (!shopBean.getPic().equals(""))
            Picasso.with(context).load(Constants.BASE_URL+shopBean.getPic()).into(shopViewHolder.imageView);
        shopViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //跳转到店铺页面
                Intent intent = new Intent(context,FoodListActivity.class);
                intent.putExtra("shop_id",shopBean.getShop_id());
                intent.putExtra("shop_name",shopBean.getShopname());
                intent.putExtra("phomenum",shopBean.getPhonenum());
                context.startActivity(intent);
            }
        });
    }

//    @Override
//    public int getItemCount() {
//        return datalist == null ? 0 : datalist.size();
//    }

    public static class shopViewHolder extends RecyclerView.ViewHolder{
        ImageView imageView;
        RatingBar res_bar;
        TextView res_name,res_address;

        public shopViewHolder(View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.res_image);
            res_name =itemView.findViewById(R.id.res_name);
            res_bar = itemView.findViewById(R.id.ratingBar1);
            res_address = itemView.findViewById(R.id.res_address);
            Log.d("调试", "onSuccess: over");
        }

    }

}


